#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
快速连接测试脚本
"""

import asyncio
import websockets
import json
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

async def quick_test():
    server_url = "ws://172.20.0.94:8080"
    
    try:
        logger.info(f"测试连接到: {server_url}")
        
        async with websockets.connect(server_url) as websocket:
            logger.info("✅ 连接成功！")
            
            # 发送认证消息
            auth_msg = {
                "type": "AUTH",
                "data": {
                    "userId": "test_android_001",
                    "username": "Android测试用户",
                    "userType": "USER",
                    "department": "测试科室"
                }
            }
            
            await websocket.send(json.dumps(auth_msg))
            logger.info("📤 认证消息已发送")
            
            # 等待响应
            response = await asyncio.wait_for(websocket.recv(), timeout=5.0)
            logger.info(f"📥 收到响应: {response}")
            
            # 发送患者上报
            patient_msg = {
                "type": "PATIENT_REPORT", 
                "data": {
                    "patientId": "TEST_001",
                    "patientName": "测试患者",
                    "reporterName": "Android测试用户",
                    "department": "内科"
                }
            }
            
            await websocket.send(json.dumps(patient_msg))
            logger.info("📤 患者上报已发送")
            
            # 等待响应
            response = await asyncio.wait_for(websocket.recv(), timeout=5.0)
            logger.info(f"📥 患者上报响应: {response}")
            
            logger.info("🎉 测试完成！服务器工作正常")
            
    except Exception as e:
        logger.error(f"❌ 连接失败: {e}")

if __name__ == "__main__":
    asyncio.run(quick_test()) 